﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HBattle
{
    public class Vehicle : MovingEntity
    {
        public Vehicle(int id):base(id)
        {
            steer = new SteeringBehaviors(this);
        }

        public Vehicle(int id, string name, float mass, float maxSpeed, float maxForce, float maxTurnRate):base(id, name, mass, maxSpeed, maxForce, maxTurnRate)
        {
            steer = new SteeringBehaviors(this);
        }

        public SteeringBehaviors steer;

        public override void Update(float deltaTime)
        {
            Vector3 force = steer.Wander();
           
            Vector3 acceleration = force / Mass;

            Velocity += acceleration * Time.deltaTime;

            if (Velocity.magnitude > MaxSpeed)
            {
                Velocity = Velocity.normalized * MaxSpeed;
            }

            CacheTransform.rotation = Quaternion.LookRotation(Velocity.normalized);
            Position = Position + Velocity * deltaTime;
        }

        public override bool HandleMessage(Telegram msg)
        {
            throw new System.NotImplementedException();
        }
    }
}
